import { LoginResponse, UserInfo } from 'admin/schema/User';
import $http from '../../../servers/http';
import { Result } from '../../schema/Result';

/* 获取验证码
---------------------------------------------------------------- */
export const getVerifyCode = (data: { captchaId: string }): Promise<any> => {
  return $http.get({
    url: `/sso/captcha`,
    data,
  });
};
/* 登录
---------------------------------------------------------------- */
export const login = (data: {
  account: string;
  pwd: string;
  captcha: string;
  captchaId: string;
  //应用标识 manager: 管理端系统； seats 坐席端系统
  appCode: 'manager' | 'seats';
}): Promise<Result<LoginResponse>> => {
  return $http.post({
    url: `/sso/login`,
    data,
  });
};

/* 退出登录
---------------------------------------------------------------- */
export const logout = (): Promise<Result<null>> => {
  return $http.put({
    url: `/sso/logout`,
  });
};

/* 设置
---------------------------------------------------------------- */
/**查询登录账户信息 */
export const getSysUserInfo = (): Promise<Result<UserInfo>> => {
  return $http.get({
    url: `/sso/user/userinfo`,
  });
};

/**修改密码 */
export const modifySysUserPwd = (oldPwd: string, newPwd: string): Promise<Result<null>> => {
  return $http.patch({
    url: '/sso/user/modifypassword',
    data: {
      oldPassword: oldPwd,
      newPassword: newPwd,
    },
  });
};

/**根据分权用户id得到外呼用户id */
export const fenQuanUserId = (orgId: string): Promise<Result<null>> => {
  return $http.get({
    url: `/sso/user/fenQuanUserId/${orgId}`,
  });
};

/**查询温馨提示弹窗显示隐藏，返回isShow：0-不显示，1-显示 */
export const getUserNoticeState = (): Promise<Result<{ isShow: 0 | 1 }>> => {
  return $http.get({
    url: '/seats/reminder',
  });
};

/**
 * 上传文件通用接口
 * @param data any
 */
export const requestUploadFile = (data: any): Promise<Result<{}>> => {
  return $http.post({
    url: `/robotmanage/voices/upload`,
    data,
  });
};

/**
 * 预签入接口
 */
export const reginfo = (): Promise<Result<any>> => {
  return $http.get({
    url: '/seats/reginfo',
  });
};

/**
 * 获取配置信息（前端配置）
 */
export const getSystemConfig = (): Promise<Result<any>> => {
  return $http.get({
    url: '/icms/systemconfig/web',
  });
};
